import { Loading } from 'element-ui';

/**
 * 配置全局loading提示框
 * 显示loading this.showLoading()
 * 关闭loading this.hideLoading()
 */
let loading = null;
const showLoading = (params) => {
    // 配置 Loading 参数
    const options = {
        lock: true,
        text: 'Loading...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    };
    loading = Loading.service(Object.assign({}, options, params));
};

const hideLoading = () => {
    if (loading) {
        setTimeout(() => {
            loading.close();
        }, 2000);
    }
};

export { showLoading, hideLoading };
